package day07;

import java.util.Random;

//生成N位验证码(字母大写,小写,数字)
//训练目标:随机数+数组+方法
public class veificationCode {
    public static void main(String[] args) {
        String code=generataVericCode(4);//生成多少位数的验证码
        System.out.println("验证码为:"+code);
    }
    public static String generataVericCode(int n){//生成n位验证码
        String code="";//验证码
        Random rd=new Random();
        char[] chs = {'a','b','c','d','e','f','g','h','i','j','k',
                'l','m','n','o','p','q','r','s','t','u','v',
                'w','x','y','z','A','B','C','D','E','F','G',
                'H','I','J','K','L','M','N','O','P','Q','R',
                'S','T','U','V','W','X','Y','Z','0','1','2',
                '3','4','5','6','7','8','9'};//验证码的可选范围(共62个)
        for (int i=0;i<n;i++){//n次
            int index= rd.nextInt(chs.length);//随机下标0-61
            code=code+chs[index];//根据随机下标获取对应的字符串并且拼接的coid中
        }
        return code;
    }
    /*
    创建一个生成验证码的方法
    调用验证码
    想生成多少位验证码就写多少
     */
    /*
    生成4四位数的验证码
    执行逻辑:
                code=""
    i=0 index=5 code=f
    i=1 index=61 code=9
    i=2 index=25 code=z
    i=3 index=60 code=8
    i=4 flase
     */
}
